/**
 * @author wn
 * @date 2023/03/06 13:19:31
 * @description: 用户权限 存储
 * 添加主界面路由
 * 刷新 routers 就没有了 所以这里不持久化 与路由保持同步
 */

import { constantRouterMap } from '@/config/router.config'

import { defineStore } from 'pinia'
import { reactive } from 'vue'

export const usePermission = defineStore('permission', () => {
	/**
	 * user/login + / + 404 + menu = 所有的路由
	 * 动态添加的路由(/ + 404 + menu)
	 * permissionList = menu
	 */
	const permission = reactive({
		routers: constantRouterMap,
		addRouters: [],
	})

	/**
	 * 添加动态路由  拼接基础路由
	 * 返回 promise
	 */
	const setRouters = async asyncRouters => {
		permission.addRouters = asyncRouters
		permission.routers = constantRouterMap.concat(asyncRouters)
		return '添加动态路由成功'
	}

	return { permission, setRouters }
})
